

const requestMode = require('../../../js/requestsMode.js');
const constants = require('../../../js/constants.js');
const session = require('../../../js/session.js');
const  Tools = require('../../../js/Tools.js');
Page({
  data:{
      placeOrderTime:"",
      sendTime:'',
      orderStatus:2,
      orderNumber:"",
      consignee:'',
      consigneePhone:'',
      GetAddress:'',
      OrderImg:'../../../images/wdl.png',
      orderName:"",
      orderPrice:'',
      senPrice:'',
      allPrice:'',
      yourOrderNumber:1,
      createTime:""
  },
    ////界面出现的时候回调
    onLoad : function (orderData) {
       // console.log("requestGetOrderId",orderData.order_id);
        let that = this;
        let order_id = orderData.order_id;
        requestMode.sendRequest("order/detail",'POST',{order_id:order_id},{sKey:session.get('sKey')}).then(function(success){
            let requestSuccessCode = success.data.code,requestSuccessData = success.data.data;
            if(requestSuccessCode == 200){
                that.setData({
                    goods_info_list : requestSuccessData.goods_info.list,
                    goodsCount :  requestSuccessData.goods_info.total,
                    goods_give_info : requestSuccessData.goods_give_info,
                    coupon_value : requestSuccessData.coupon_value,
                    goods_give_info_list : requestSuccessData.goods_give_info.list,
                    orderPrice : requestSuccessData.total_fee,
                    senPrice : requestSuccessData.freight,
                    allPrice :  requestSuccessData.real_pay,
                    full_cut_value : requestSuccessData.full_cut_value,
                    order_id : order_id,
                    order_status : requestSuccessData.status,
                    address_info : requestSuccessData.address_info,
                    order_number : requestSuccessData.order_number,
                    pay_type : requestSuccessData.pay_type,
                    createTime : requestSuccessData.other.create_time
                })
            }else{
                Tools.showErrorToast(success.data.message)
            }
        }, function (fail) {
            Tools.showWrongNetWorkToast();
        });
      //  console.log("orderInfo==>",orderData.orderInfo);
    },
    cancelOrder: function () {
        let that = this;
        wx.showModal({
            content: '您确定取消此订单吗？',
            success: function (res) {
                if (res.confirm) {
                    Tools.showLoaddingDefault();
                    requestMode.sendRequest('order/remove','POST',{order_id:that.data.order_id},{sKey:session.get('sKey')}).then(function (removeOrderSuccess) {
                        let getCode = removeOrderSuccess.data.code;
                        if(getCode == 200){
                            Tools.showSuccessInfoToast('操作成功');
                            Tools.hideLoaddingToast();
                            wx.reLaunch({
                                url:'../../type/type'
                            });
                        }else{
                            Tools.showErrorToast(removeOrderSuccess.data.message);
                        }
                    },function(){
                        Tools.showWrongNetWorkToast();
                    })
                }
            }
        });
    },
    payNow:function(){
        let that = this;
        requestMode.sendRequest('order/pay','POST',{order_id : that.data.order_id},{sKey:session.get('sKey')}).then(function(res){
            let getData = res.data;
            if(res.data.code == 200){
                wx.requestPayment({
                    appId:getData.data.appId,
                    'timeStamp': getData.data.timeStamp,
                    'nonceStr':getData.data.nonceStr,
                    'package': getData.data.package,    //  支付id
                    'signType':getData.data.signType,
                    'paySign': getData.data.paySign,
                    success:function(res){
                      /* wx.redirectTo({
                           url:'../seeMinesOrder/seeMinesOrder?type=1'
                       })*/
                        Tools.showSuccessInfoToast("支付成功！");
                        setTimeout(function () {
                            wx.reLaunch({
                                url:'../../type/type'
                            });
                        },1000);
                       /* setTimeout(function () {
                            wx.navigateBack({
                                delta: 2
                            })
                        },800)*/
                    },
                    fail:function(res){
                        Tools.showErrorToast("支付失败！");
                       /* wx.redirectTo({
                            url:'../seeMinesOrder/seeMinesOrder?type=0'
                        })*/
                        setTimeout(function () {
                            wx.reLaunch({
                                url:'../../type/type'
                            });
                        },1000)
                    }
                })
            }else{
                Tools.showErrorToast('支付失败');
               /* wx.redirectTo({
                    url:'../seeMinesOrder/seeMinesOrder?type=0'
                })*/
                setTimeout(function () {
                    wx.reLaunch({
                        url:'../../type/type'
                    });
                },1000);
            }
        },function(fail){
            Tools.showWrongNetWorkToast();
        })
    }
});